package com.crysta1.aitrans;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

public class ResultDialog extends Dialog {

    private float score;
    private String feedback;
    private FinishListener finishListener;

    public ResultDialog(Context context, float score, String feedback) {
        super(context);
        this.score = score;
        this.feedback = feedback;
    }

    public interface FinishListener {
        void onFinish();
    }

    public void setFinishListener(FinishListener listener) {
        this.finishListener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_result);

        TextView tvScore = findViewById(R.id.tvScore);
        TextView tvFeedback = findViewById(R.id.tvFeedback);
        Button btnFinish = findViewById(R.id.btnFinish);

        tvScore.setText(String.format("得分: %.2f/10", score));
        tvFeedback.setText(feedback);

        btnFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (finishListener != null) {
                    finishListener.onFinish();
                }
            }
        });
    }
}